﻿@{
    ViewBag.Title = "产品-首页";
}

<div class="row">
    <div>
        
    </div>
    <div>
        <table class="table table-bordered table-striped ">
            <thead>
                <tr>
                    <th>操作</th>
                    <th>标题</th>
                    <th>编号</th>
                    <th>状态</th>
                    <th>注册日期</th>
                    <th>备注</th>
                    <th>类型编号</th>
                    <th>类型名称</th>
                </tr>
            </thead>
            
            <tbody id="tabBody">
            
            </tbody>
        </table>  

    </div>
</div>
<div class="row"></div>
<div class="row"></div>

@section scripts
{
    <script>
        $(function() {
            loadData();




            
        });

        //加载数据
        function loadData() {
            $.ajax({
                url: "/product/list",
                data: {},
                success: function (res) {
                    var htmlStr = "";
                    for (var i = 0; i < res.length; i++) {
                        var r = res[i];
                        var tr = "<tr><td><button value='" +
                            r.Id +"' class='btn btn-sm'>删除</button><a class='btn btn-sm' href='/product/edit/" +
                            r.Id +"'>编辑</a></td><td>" +
                            r.Title +"</td><td>" +
                            r.Code +"</td><td>" +
                            r.Status +"</td><td>" +
                            (r.RegDate || "") +"</td><td>" +
                            (r.Remark || "") +"</td><td>" +
                            r.CateCode +"</td><td>" +
                            r.CateTitle +"</td></tr>";

                        htmlStr += tr;
                    }
                    $("#tabBody").html(htmlStr);
                    bindClick();
                },
                error: function (r) {
                    alert("请求出错");
                }
            });
        }

        //绑定点击事件
        function bindClick() {
            $("button.btn-sm").click(function () {
                var r = confirm("删除后数据无法找回，是否要删除?", "请注意");
                if (r) {
                    alert("删除方法未实现");
                }
            });
        }
    </script>
}
